home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c++-part1 / 5119 < prev    next >
Encoding:
Internet Message Format  |  1996-08-06  |  2.7 KB

  1. Path: newsroom.hitc.com!usenet
  2. From: psand@eos.hitc.com (G. Patrick Sand)
  3. Newsgroups: comp.lang.c++
  4. Subject: Re: simple design question
  5. Date: 2 Feb 1996 16:34:42 GMT
  6. Organization: Hughes Aircraft (EOSDIS)
  7. Message-ID: <4etef2$3sc@newsroom.hitc.com>
  8. References: <DM4u8I.G1H@emr1.emr.ca>
  9. NNTP-Posting-Host: 155.157.118.56
  10. Mime-Version: 1.0
  11. X-Newsreader: WinVN 0.99.3
  12.  
  13. In article <DM4u8I.G1H@emr1.emr.ca>, jagrant@emr1.emr.ca says...
  14. >
  15. >This is a design question, not a syntax question, so forgive the pseudo-
  16. >code.
  17. >
  18. >I'm trying to design/write a class for complex file I/O (I'll state it
  19. >in simple terms here).
  20. >
  21. >I want to use it like this:
  22. >        object.Open("xxx")
  23. >        for(...){
  24. >          object.Read(stuff);
  25. >        }
  26. >        object.Close();
  27. >
  28. >But I want to also have a single function that will Open/Read/Close in a
  29. >single operation:
  30. >        object.GetData("xxx",stuff);
  31. >
  32.  
  33. Okay, the first question is this:
  34.  
  35. 1. Do you want to reuse the open/close/read semantics in other classes?
  36.  
  37. If so, make it a separate class and use inheritance to add it to classes 
  38. where you wish to do complex I/O.  If not, just make them methods in the 
  39. desired class.  I recommend that if you have 2 or more classes which will 
  40. do this I/O create the I/O operations as a separate class and 
  41. inherit--this is one of the maintenance blessing C++ and OOA/D confers on 
  42. you...if you use it...
  43.  
  44. The second question is this:
  45.  
  46. 2. Why not use the iostreams/fstreams stuff?  It does deal with 
  47. clashes-like calling Open() then GetData()...although you will need to do 
  48. some checking... This can be put into a separate class or built into the 
  49. methods and save you some hassles...iostreams is very powerful, and a bit 
  50. daunting at first, but as I'm learning it I am starting to prefer it over 
  51. the printf/scanf functions I mastered in C...
  52.  
  53. You might also want to have a separate class for the I/O and include 
  54. state variables (i.e., attributes in OOD-speak) to indicate if you have a 
  55. file, have it open, or have closed it....It looks like a string (or char 
  56. pointer) for the filename and an int for SELECTED/OPENED/CLOSED/NONE...
  57.  
  58. Might as well experiment with this stuff now, it's cheap (just time and 
  59. electricity on your computer) and will benefit you greatly as you dig 
  60. deeper into C++....
  61.  
  62. BTW, I'm going to finally break down and buy and book on iostreams; I've 
  63. reached the point where my needs exceed the usual discussions in the C++ 
  64. books...
  65.  
  66. Hope this helps...
  67. -- 
  68. G. Patrick Sand
  69. psand@eos.hitc.com
  70. PatSand@aol.com
  71. (301) 925-0791
  72. "Travel Light But Right..."
  73. Microsoft Network is prohibited from redistributing 
  74. this work in any form, in whole or in part.   License 
  75. to distribute this individual post is available to Microsoft
  76. for $999. Posting without permission constitutes an 
  77. agreement to these terms...gps
  78.  
  79.